// pages/ShouYiMingXi/ShouYiMingXi.js
var util = require('../../utils/util.js')
const Monitor = require('../../utils/monitor.js').Monitor
Page(Monitor.hookApp({
  data: {
    imgUrls: getApp().globalData.imgUrls,
    list: [],
    showNum: 9,
    page: 1,
    currentTab: 0,
    loading: false,
    arr: ['全部', '一级提成', '用户提成']
  },
  click(e) {
    var e = e.currentTarget.dataset.current
    if (this.data.currentTab == e) {

    } else {
      this.setData({
        currentTab: e
      })
    }
  },

  onLoad: function(options) {
    // this.orderList()
  },
  onShow() {
    this.orderList()
  },

  onReachBottom() {
    this.setData({
      page: this.data.page + 1
    })
    this.orderList()
  },

  orderList() {
    util.API('pyapi/distribute_income_record', {
      page: this.data.page,
      pageshow: 9,
    }, 'application/x-www-form-urlencoded').then(res => {
      let {
        midnight,
        code,
        data,
        day_count,
        month_count,
        msg,
      } = res
      if (code == 200) {
        data = data.map(item => {
          let dateObj = util.getTimeDian(item.create_time)
          item.date = `${dateObj.y}-${dateObj.m}-${dateObj.d} ${dateObj.h}:${dateObj.i}`
          return item
        })
        this.setData({
          midnight,
          list: this.data.list.concat(data),
          day_count,
          month_count
        })
      } else {
        wx.showToast({
          title: msg + '',
          icon: 'none'
        })
      }
    })
  }
}))